﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThuVienCT;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace QLCTNA
{
    public delegate void Login (object sender, InfoLogin e);

    public class InfoLogin : EventArgs
    {
        public string User { get; set; }

        public string Name { get; set; }

        public byte Info { get; set; }
    }

    public class Connection
    {
        static public ConnectionData Connect()
        {
            ConnectionData cnn = null;
            FileText ft = new FileText("Config\\Config.ini");
            if (ft.ReadConfig("DatabaseFile", "ok") == "1")
            {
                string connection = Application.StartupPath + "\\" + ft.ReadConfig("DatabaseFile", "path");
                cnn = new ConnectionData(connection);
                return cnn;
            }
            else
            {
                string server = ft.ReadConfig("Database", "server");
                string database = ft.ReadConfig("Database", "database");
                if (!string.IsNullOrEmpty(ft.ReadConfig("Database", "user")))
                {
                    string user = null;
                    string password = "";
                    user = ft.ReadConfig("Database", "user");
                    if (ft.ReadConfig("Database", "password") != null)
                    {
                        password = ft.ReadConfig("Database", "password");
                    }
                    cnn = new ConnectionData(server, database, user, password);
                    return cnn;
                }
                cnn = new ConnectionData(server, database);
                return cnn;
            }
        }
    }
}


